using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Mail;

namespace OnlineAnadolu
{
    public class Mail
    {

        public bool MailGonder(string kime, string MessageBody)
        {
            try
            {
                string[] receivers = new string[] { kime };

                for (int i = 0; i < receivers.Length; i++)
                {

                    System.Net.Mail.MailAddress Sender = new System.Net.Mail.MailAddress("ounal86@gmail.com", "Anadolu Bazaar");

                    System.Net.Mail.MailAddress Receiver = new System.Net.Mail.MailAddress(receivers[i]);

                    System.Net.Mail.MailMessage Email = new System.Net.Mail.MailMessage(Sender, Receiver);

                    Email.IsBodyHtml = true;

                    Email.Headers.Add("charset", "iso-8859-9");

                    Email.Subject = "Mail Gonderme";

                    string MailMesaj = "<font face='Tahoma' size='2'><br />" + MessageBody + "</font>";

                    Email.Body = MailMesaj;

                    System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("anadolubazaar", "idmproje7");

                    System.Net.Mail.SmtpClient MailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com",587);
                    
                    //MailClient.Host = "mail.yahoo.com";
                   MailClient.EnableSsl = true;

                    MailClient.UseDefaultCredentials = false;

                   MailClient.Credentials = basicAuthenticationInfo;

                    MailClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                    //MailClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.PickupDirectoryFromIis;

                    MailClient.Send(Email);


                }
                return true;
            }

            catch (Exception ex)
            {
                return false;
            }


        }

    }
}
